/**
 * Created by Administrator on 2016-10-20.
 * 订单详情显示
 */
$(function () {
    var NAMESPACE = 'myOrderLayer';

    function OrderLayer(ele, opt) {
        this.$element = $(ele);
        this.settings = $.extend({}, OrderLayer.defaults, $.isPlainObject(opt) && opt);
        this.init();
    }

    OrderLayer.defaults = {
        //表格元素
        id: "",
        title: "",
        orderid: 0
    };

    OrderLayer.prototype = {
        _id: null,
        _op_orderLayer: null,

        _orderid: 0,
        _printfileURL:"",

        constructor: OrderLayer,

        init: function () {
            this._id = this.settings.id;
            _op_orderLayer = this;

            this.create();
            this.bindEvent();
        },

        create: function () {
            //初始化元素
            this.InitializeElement();
        },

        bindEvent: function () {
            this.registerorderclose();
        },

        //初始化元素
        InitializeElement: function () {
            $("#" + this._id).empty();
            var shtml = "";
            shtml += "<div class=\"examination-tit ieexamination-tit\">";
            shtml += "  <div class=\"row\">";
            shtml += "    <div class=\"col-md-11 ie8width800\"><span>"+ _op_orderLayer.settings.title +"</span></div>";
            shtml += "    <div id=\"ordercloseDetail\" class=\"col-md-1 ie8width100 close\"><span>×</span></div>";
            shtml += "    <div class=\"clear\"></div>";
            shtml += "  </div>";
            shtml += "</div>";
            shtml += "<div class=\"examination-con\">";
            shtml += "  <div class=\"row\">";
            // shtml += "<div class=\"col-md-12 iewidth860\" style=\"margin-top:10px;\">";
            // shtml += "<strong style=\"line-height:26px;\" class=\"ordertext floatl\">订单脚印：</strong><div id=\"orderStepByList\" class=\"floatl\"><div/>";
            // shtml += "</div>";
            //
            // shtml += "</div>";
            shtml += "<div class=\"col-md-12 iewidth860\">";
            shtml += "<div class=\"examline\">";
            shtml += "<div class=\"exam-tit\">合同信息</div>";
            shtml += "</div>";
            shtml += "</div>";


            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">甲方：</strong><span id=\"contractcompanya2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">乙方：</strong><span id=\"contractcompanyb2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">履行开始时间：</strong><span id=\"getFactoryConbegintime2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">履行结束时间：</strong><span id=\"getFactoryConendtime2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">合同金额：</strong><span style='color: #E4393C;padding: 0 5px;' id=\"contractmoney2\"></span>元";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">合同编号：</strong><span id=\"contractno2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">合同附件：</strong><a id=\"attach2\">查看附件</a>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">当前部门名称：</strong><span id=\"currentdeptname2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">当前步骤名称：</strong><span id=\"currentprogressname2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">联系人：</strong><span id=\"linkman2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">联系电话：</strong><span id=\"linkphone2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">受理人：</strong><span id=\"lockmanname2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-12 iewidth860\" style=\"margin-top:10px;\">";
            shtml += "<strong style=\"line-height:26px;\" class=\"ordertext floatl\">步骤列表：</strong>" +
                "<div id=\"orderStepByList\" class=\"floatl\">"
                    shtml += "<div id=\"factoryList\">"
                        shtml += "<table class=\"table table-bordered table-hover\" style='margin-bottom: 0px'>"
                        shtml += "<thead>"
                        shtml += "<tr>"
                        shtml += "<th style=\"display: none\">#</th>"
                        shtml += "<th>步骤名称</th>"
                        shtml += "<th>负责部门</th>"
                        shtml += "<th>提交内容</th>"
                        shtml += "<th>备注</th>"
                        shtml += "<th>提交时间</th>"
                        shtml += "</tr>"
                        shtml += "</thead>"
                        shtml += "<tbody id=\"processListMyGrid\">"

                        shtml += "</tbody>"
                        shtml += "</table>"
                    shtml += "</div>"
                "<div/>";
            shtml += "</div>";
            shtml += "</div>";
            shtml += "<div class=\"clear\"></div>";
            shtml += "    <div class=\"col-md-12\" style=\"margin-top:20px;\">";
            shtml += "      <div class=\"examline\">";
            shtml += "        <div class=\"exam-tit\">上一步操作信息</div>";
            shtml += "      </div>";
            shtml += "    </div>";
            shtml += "<div class=\"col-md-12 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong  class=\"ordertext\">前提交内容：</strong><span id=\"prevcontent2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\" id=\"fileProcessMan-m\">";
            shtml += "<strong class=\"ordertext\" id=\"prevdeptname\">前提交部门：</strong><span id=\"prevdeptname2\"></span>";
            shtml += "</div>";
            shtml += "<div class=\"col-md-6 iewidth420\" style=\"margin-top:10px\">";
            shtml += "<strong class=\"ordertext\">前提交人：</strong><span id=\"prevmanname2\"></span>";
            shtml += "</div>";


            shtml += "<div class=\"clear\"></div>";
            shtml +="</div>";
            shtml += "<div class=\"col-md-12\" style=\"margin-top:20px;margin-left: -35px\">";
            shtml += "<div class=\"form-group\">";
            shtml += "<button id=\"addressExitDetail\" type=\"submit\" class=\"btn btn-primary\">关 闭</button>";
            shtml += "</div>";
            shtml += "</div>";
            shtml += "</div>";
            shtml += "</div>";



            $("#" + this._id).append(shtml);

        },

        //关闭按钮事件
        registerorderclose: function () {
            $("#ordercloseDetail,#addressExitDetail").click(function () {
                $("#" + _op_orderLayer._id).hide();
                $("#gray_bg").hide();
            });
        },
        //获取订单信息并赋值
        viewOrder: function (orderid) {
            _op_orderLayer._orderid = orderid;

            var url = 'apis/contract/getcontractdetail';

           $.ajax({
               url: url,
               type: 'post',
               data: {
                   "idContract": orderid

               },
               success: function (data, status, xhr) {
                   // console.log(data);
                   var dataContract = data.data;
                   $("#contractcompanya2").html(dataContract.contractcompanya);
                   $("#contractcompanyb2").html(dataContract.contractcompanyb);
                   $("#contractno2").html(dataContract.contractno);
                   $("#contractmoney2").html(dataContract.contractmoney);
                   $("#getFactoryConbegintime2").html(dataContract.contractbegintime.substring(0,10));
                   $("#getFactoryConendtime2").html(dataContract.contractendtime.substring(0,10));
                   $("#attach2").attr('href',dataContract.attach);
                   $("#currentdeptname2").html(dataContract.currentdeptname);
                   $("#currentprogressname2").html(dataContract.currentprogressname);
                   $("#linkman2").html(dataContract.linkman);
                   $("#linkphone2").html(dataContract.linkphone);
                   $("#lockmanname2").html(dataContract.lockmanname);
                   $("#prevcontent2").html(dataContract.prevcontent);
                   $("#prevdeptname2").html(dataContract.prevdeptname);
                   $("#prevmanname2").html(dataContract.prevmanname);
                   //步骤列表
                   var html = "";
                   var datas = dataContract.items;
                   for (var i = 0; i < datas.length; i++) {
                       html += '<tr itemvalue="' + datas[i].idprogress + '" idoperatdeptItem="' + datas[i].iddept + '"> ' +
                           '<td style="display: none">' + datas[i].idprogress + '</td> ' +
                           '<td>' + datas[i].progressname + '</td> ' +
//                        '<td style="display: none">'+datas[i].iddept+'</td> ' +
                           '<td>' + datas[i].deptname + '</td> ' +
                           '<td>' + datas[i].content + '</td> ' +
                           '<td>' + datas[i].remark + '</td> ' +
                           '<td>' + datas[i].createtime.substring(0,19) + '</td> ' +
                           '</tr>';
                   }

                   $("#processListMyGrid").html(html);



               },
               error: function (res) {
                   alert(res.msg);
               }

           });
        }
    };

    $.fn.orderlayer = function (option,success) {
        var args = [].slice.call(arguments, 1);

        return this.each(function () {
            var $this = $(this);
            var data = $this.data(NAMESPACE);
            var options;
            var fn;

            if (!data) {
                if (/destroy/.test(option)) {
                    return;
                }

                options = $.extend({}, $this.data(), $.isPlainObject(option) && option);
                $this.data(NAMESPACE, (data = new OrderLayer(this, options)));
            }

            if (typeof option === 'string' && $.isFunction(fn = data[option])) {
                fn.apply(data, args);
            }
        });

        // var grid = new dataGrid(this, options);
        // return this.each(function () {
        //     grid.init();
        // });
    };

    $.fn.orderlayer.Constructor = OrderLayer;

});